import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/values/colors.dart';

import '../index.dart';

class HeadContent extends GetView<WalletController> {
  final VoidCallback onWithdrawal;
  final VoidCallback onRecharge;

  const HeadContent({
    super.key,
    required this.onWithdrawal,
    required this.onRecharge,
  });

  @override
  Widget build(BuildContext context) {
    return _buildWrap(
      children: [
        _buildMoney(),
        const SizedBox(height: 25),
        _buildBtns(),
      ],
    );
  }

  Widget _buildBtns() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        _buildBtnItem(
          text: '提现',
          backgroundColor: AppColors.danger,
          onPressed: onWithdrawal,
        ),
        const SizedBox(width: 20),
        _buildBtnItem(
          text: '充值',
          backgroundColor: AppColors.success,
          onPressed: onRecharge,
        ),
      ],
    );
  }

  Widget _buildBtnItem({
    required String text,
    required VoidCallback onPressed,
    required Color backgroundColor,
  }) {
    return SizedBox(
      width: 100,
      height: 40,
      child: ElevatedButton(
        onPressed: onPressed,
        style: ElevatedButton.styleFrom(
          backgroundColor: backgroundColor,
          foregroundColor: Colors.white,
          shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(4)),
          ),
        ),
        child: Text(text),
      ),
    );
  }

  Widget _buildMoney() {
    return RichText(
      text: const TextSpan(
        text: '2000',
        style: TextStyle(
          color: Color(0xFF101010),
          fontSize: 48,
          fontWeight: FontWeight.w500,
        ),
        children: [
          TextSpan(
            text: '读币',
            style: TextStyle(
              color: AppColors.active,
              fontSize: 16,
              fontWeight: FontWeight.normal,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildWrap({required List<Widget> children}) {
    return Stack(
      children: [
        Positioned(
          bottom: Platform.isIOS ? kToolbarHeight : kTabbarHeight,
          left: 0,
          right: 0,
          child: SizedBox(
            height: kHeaderHeight,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: children,
            ),
          ),
        ),
      ],
    );
  }
}
